package jjn.acwing.algorithm_basic.chapter1.sort;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Jiang Jining
 * @since 2023-09-15 22:56
 */
public class Acwing786 {
    static int quickSort(int[] array, int left, int right, int k) {
        if (left >= right) {
            return array[left];
        }
        int i = left - 1;
        int j = right + 1;
        int x = array[i + j >> 1];
        while (i < j) {
            while (array[++i] < x)
                ;
            while (array[--j] > x)
                ;
            if (i < j) {
                int temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
        if (j - left + 1 >= k) {
            return quickSort(array, left, j, k);
        }
        return quickSort(array, j + 1, right, k - (j - left + 1));
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String firstLine = bufferedReader.readLine();
        String[] nums = firstLine.split(" ");
        int n = Integer.parseInt(nums[0]);
        int k = Integer.parseInt(nums[1]);
        String secondLine = bufferedReader.readLine();
        int[] array = new int[n];
        String[] s = secondLine.split(" ");
        for (int i = 0; i < n; i++) {
            array[i] = Integer.parseInt(s[i]);
        }
        System.out.println(quickSort(array, 0, array.length - 1, k));
    }
}
